package us.icitap.timsportal.entity;

import java.io.Serializable;
import java.lang.String;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.persistence.*;

/**
 * Entity implementation class for Entity: Module
 *
 */
@Entity
@Table(schema="TIMSPORTAL", name="MODULE")
@SequenceGenerator(name = "module_seq", sequenceName = "TIMSPORTAL.SQ_TIMSPORTAL_MODULE", allocationSize = 1)
public class Module implements Serializable {

	
	/**
	 * 
	 */
	private static final long serialVersionUID = 8060705130027956969L;
	
	private Integer id;
	private String moduleName;
	private String moduleURL;
	private String devModuleURL;
	private Date recordDate;
	private String recordUser;
	private Integer status;
	private Set<Role> roles;	
	private Set<OrgStructure> orgStructures = new HashSet<OrgStructure>();

	public Module() {
		super();
	}   
	
	@Id
	@GeneratedValue(generator="module_seq")
	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}
	
	@Column(name="MODULE_NAME")
	public String getModuleName() {
		return this.moduleName;
	}

	public void setModuleName(String moduleName) {
		this.moduleName = moduleName;
	}
	@Column(name="MODULE_URL")
	public String getModuleURL() {
		return this.moduleURL;
	}
	
	@Column(name="DEV_MODULE_URL")
	public String getDevModuleURL() {
		return devModuleURL;
	}
	public void setDevModuleURL(String devModuleURL) {
		this.devModuleURL = devModuleURL;
	}

	public void setModuleURL(String moduleURL) {
		this.moduleURL = moduleURL;
	}
	
	@Temporal( TemporalType.DATE)
	@Column(name="RECORD_DATE")
	public Date getRecordDate() {
		return this.recordDate;
	}

	public void setRecordDate(Date recordDate) {
		this.recordDate = recordDate;
	}
	@Column(name="RECORD_USER")
	public String getRecordUser() {
		return this.recordUser;
	}

	public void setRecordUser(String recordUser) {
		this.recordUser = recordUser;
	}   
	public Integer getStatus() {
		return this.status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	@OneToMany(fetch=FetchType.EAGER , mappedBy="module", cascade=CascadeType.ALL)
	public Set<Role> getRoles() {		
		return roles;
	}
	
	public void setRoles(Set<Role> roles) {
		Set<Role> r = new HashSet<Role>();
		if(r!=null)
		r.addAll(roles);		
		this.roles = r;
	}

	
	@ManyToMany(cascade={CascadeType.ALL},fetch=FetchType.EAGER)
	@JoinTable(name="TIMSPORTAL.ORG_MODULE", 
			joinColumns={@JoinColumn(name="MODULE_ID")},
			inverseJoinColumns={@JoinColumn(name="ORG_ID")}	)
	public Set<OrgStructure> getOrgStructures() {
		return orgStructures;
	}
	
	public void setOrgStructures(Set<OrgStructure> orgStructures) {
		HashSet<OrgStructure> r = new HashSet<OrgStructure>();
		if(r!=null)
			r.addAll(orgStructures);
		this.orgStructures = r;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((devModuleURL == null) ? 0 : devModuleURL.hashCode());
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result
				+ ((moduleName == null) ? 0 : moduleName.hashCode());
		result = prime * result
				+ ((moduleURL == null) ? 0 : moduleURL.hashCode());
		result = prime * result + ((status == null) ? 0 : status.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof Module))
			return false;
		Module other = (Module) obj;
		if (devModuleURL == null) {
			if (other.devModuleURL != null)
				return false;
		} else if (!devModuleURL.equals(other.devModuleURL))
			return false;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (moduleName == null) {
			if (other.moduleName != null)
				return false;
		} else if (!moduleName.equals(other.moduleName))
			return false;
		if (moduleURL == null) {
			if (other.moduleURL != null)
				return false;
		} else if (!moduleURL.equals(other.moduleURL))
			return false;
		if (status == null) {
			if (other.status != null)
				return false;
		} else if (!status.equals(other.status))
			return false;
		return true;
	}
   
}
